﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Business;
using System.Resources;

namespace University.Workshop.WinApp
{
    public partial class AdministratorView : TemplateForm
    {
        private ResourceManager resours;
        public AdministratorView()
        {
            InitializeComponent();
            dataAdmi.Rows.Clear();
            AdministratorManager.GetAllAdministrators(dataAdmi);
            resours = new ResourceManager(typeof(RegisterAdministrator));
        }

        private void modificarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!(dataAdmi.Rows.Count-1 > 0) && !(dataAdmi.SelectedRows.Count > 1))
            {
                   string caption = this.resours.GetString("messageBox.Caption");
                    MessageBoxButtons buttons = MessageBoxButtons.OK;
                    MessageBox.Show(this, "rows select is invalid", caption, buttons, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
            }
            else
            {
                DataGridViewCell selectUserName = dataAdmi.CurrentRow.Cells[0];
                DataGridViewCell selectPassword = dataAdmi.CurrentRow.Cells[1];
                string userSelect = selectUserName.Value.ToString();
                string passwordSelect = selectPassword.Value.ToString();
                try
                {
                    RegisterAdministrator register = new RegisterAdministrator(userSelect,passwordSelect);
                    register.WindowState = FormWindowState.Normal;
                    register.StartPosition = FormStartPosition.CenterScreen;
                    register.ShowDialog();
                }
                catch (ArgumentException ex)
                {
                    string message = ex.Message;
                    string caption = this.resours.GetString("messageBox.Caption");
                    MessageBoxButtons buttons = MessageBoxButtons.OK;
                    MessageBox.Show(this, message, caption, buttons, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
                }
                AdministratorView_Load(sender, e);
            }
        }

        private void AdministratorView_Load(object sender, EventArgs e)
        {
            dataAdmi.Rows.Clear();
            AdministratorManager.GetAllAdministrators(dataAdmi);
        }

        private void dataAdmi_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 4)
            {
                if (!(dataAdmi.Rows.Count - 1 > 0) && !(dataAdmi.SelectedRows.Count > 1))
                {
                    string caption = this.resours.GetString("messageBox.Caption");
                    MessageBoxButtons buttons = MessageBoxButtons.OK;
                    MessageBox.Show(this, "rows select is invalid", caption, buttons, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
                }
                else
                {
                    DataGridViewCell selectUserName = dataAdmi.CurrentRow.Cells["Email"];
                    string emailSelect = selectUserName.Value.ToString();
                    TestEmail sendMail = new TestEmail(emailSelect);
                    sendMail.ShowDialog();
                }
            }
        }
    }
}
